package com.cee.admin.modules.ggc.controller;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.cee.common.core.query.BasePageQuery;
import com.cee.common.web.result.Result;
import com.cee.domain.modules.ggc.form.add.GgcGwpFactorAddForm;
import com.cee.domain.modules.ggc.form.update.GgcGwpFactorUpdateForm;
import com.cee.domain.modules.ggc.vo.GgcGwpFactorVo;
import com.cee.ds.modules.ggc.service.IGgcGwpFactorService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import com.cee.admin.common.BaseController;

import javax.validation.Valid;
/**
 * <p>
 * GWP系数 前端控制器
 * </p>
 *
 * @author autoGenerator
 * @since 2023-12-22
 */
@RestController
@RequestMapping("/api/v1/greenhouseGas/compute/factor/gwp")
@Tag(name = "温室气体排放计算工具-GWP系数维护")
public class GgcGwpFactorController extends BaseController {

    @Autowired
    private IGgcGwpFactorService gwpFactorService;

    @GetMapping("/page")
    @Operation(summary = "分页")
    public Result<Page<GgcGwpFactorVo>> page(BasePageQuery<GgcGwpFactorVo> query, String gasName) {
        GgcGwpFactorVo vo = new GgcGwpFactorVo();
        vo.setGasName(gasName);
        return success(gwpFactorService.queryPageVo(query.generatePage(), vo));
    }

    @PostMapping("/add")
    @Operation(summary = "添加")
    public Result<Boolean> add(@RequestBody @Valid GgcGwpFactorUpdateForm addForm) {
        return success(gwpFactorService.save(addForm.toEntity()));
    }

    @PostMapping("/update")
    @Operation(summary = "更新")
    public Result<Boolean> update(@RequestBody @Valid GgcGwpFactorAddForm updateForm) {
        return success(gwpFactorService.updateById(updateForm.toEntity()));
    }

    @DeleteMapping("/delete/{id}")
    @Operation(summary = "删除")
    public Result<Boolean> delete(@PathVariable("id") Integer id)  {
        return success(gwpFactorService.removeById(id));
    }

}

